package com.ctgu.牛客网.简单排序;

import java.io.*;
import java.util.Arrays;

/**
 * @author: Backdiy
 * @data: 2021/4/2 15:35
 * @desc: 火星人
 */
public class 火星人 {
    static int[] nums;
    static int n, m;

    public static void main(String[] args) throws IOException {
        n = Input1.nextInt();
        m = Input1.nextInt();
        nums = new int[n + 5];
        for (int i = 0; i < n; i++) {
            nums[i] = Input1.nextInt();
        }
        for (int i = 0; i < m; i++) {
            nextPer();
            Input1.out.println(Arrays.toString(nums));
        }
        for (int i = 0; i < n; i++) {
            Input1.out.print(nums[i] + " ");
        }
        Input1.out.flush();
    }

    static public void nextPer() {
        int max = n-1;
        for (int i = n - 1; i > 0; i--) {
            if (nums[i] > nums[i - 1]) {
                max = i;
                break;
            }
        }
        int x = max - 1;
        int y = max;
        for (int i = y; i < n; i++) {
            if(nums[x] < nums[i] && nums[i] < nums[y]){
                y = i;
            }
        }
        swap(x,y);
        Arrays.sort(nums,x+1,n);
    }

    static public void swap(int i, int j) {
        int t = nums[i];
        nums[i] = nums[j];
        nums[j] = t;
    }
}

class Input1 {
    static StreamTokenizer streamTokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    static String readLine() throws IOException {
        return bufferedReader.readLine();
    }

    static double nextDouble() throws IOException {
        streamTokenizer.nextToken();
        return (double) streamTokenizer.nval;
    }

    static int nextInt() throws IOException {
        streamTokenizer.nextToken();
        return (int) streamTokenizer.nval;
    }
}